<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		
		<script>
			
			var proto = Array.prototype,
				slice = proto.slice,
				mutatorMethods = [
					'pop',
					'push',
					'reverse',
					'shift',
					'unshift',
					'splice',
					'sort'
				]
			
			function arrMethodDef(arr, callback) {
				mutatorMethods.forEach(function(method) {
					arr[method] = function() {
						proto[method].apply(this, arguments)
						callback({
							event: method,
							args: slice.call(arguments),
							array: arr
						})
					}
				})
			}
			
			var arrValue = ['a'];
			
			arrMethodDef(arrValue, function(options) {
				if(options.event === 'push') {
					console.log('新数组为：\n');
					console.log(arrValue);
					console.log('数组末尾增加了' + options.args);
				}
			})
			
			arrValue.push('b');
			
		</script> 
		
	</body>
</html>
